package com.monster.servlet.player;

import com.monster.pojo.Song;
import com.monster.pojo.User;
import com.monster.service.PlayerService;
import com.monster.service.PlayerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet("/music/list_player")
public class ListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PlayerService ps = new PlayerServiceImpl();
        HttpSession session = request.getSession();
        User user = null;
        ArrayList<Song> songs = null;
        if (session.getAttribute("user") != null) {
            user = (User) session.getAttribute("user");
            songs = ps.listUserPlay(user.getId());
            session.setAttribute("playSongs", songs);       // 播放列表
        }
        request.getRequestDispatcher("playerList.jsp").forward(request, response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
